package com.cn.zpark;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: ServletConfigDemo03
 * @Description:
 * @author: RZS
 * @date: 2022/4/8  10:12
 */
@WebServlet(value = "/sc3.do", initParams = {
        @WebInitParam(name = "uname", value = "李四"),
        @WebInitParam(name = "password", value = "888888")
})
public class ServletConfigDemo03 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取当前servlet的config对象
        ServletConfig servletConfig = this.getServletConfig();
        // 获取初始化参数
        System.out.println(servletConfig.getInitParameter("uname") + " : " +
                servletConfig.getInitParameter("password"));

    }
}
